import { Bk_Product } from 'src/product/bk_product.entity';
import { Bk_User } from 'src/users/bk_user.entity';
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, Index, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';

@Entity()
export class Bk_Order {
    @PrimaryGeneratedColumn()
    id: number;

    // 创建时间
    @CreateDateColumn()
    created_at: Date;

    // 更新时间
    @UpdateDateColumn()
    updated_at: Date;

    @ManyToOne(() => Bk_User, user => user.id)
    buyer_id: Bk_User;//用户id

    // 购买方式
    @Column({ nullable: true })
    pay_method: string;

    // 支付状态
    @Column({ default: 'NOTPAY' })
    pay_state: string;

    // 支付状态描述
    @Column({ default: '未支付' })
    pay_state_desc: string;

    // 支付完成时间
    @Column({ nullable: true })
    pay_success_time: string;

    // 实付金额
    @Column({ type: "decimal", nullable: false, default: 0 })
    receipt_price: number;

    // 订单金额
    @Column({ type: "decimal", nullable: false })
    buy_price: number;

    @Index({ unique: true })
    @Column()//服务器生成订单号
    order_number: string;

    @Column() //商品名称
    product_name: string;

    // 删除时间
    @DeleteDateColumn({ nullable: true, select: false })
    deleted_at: Date;

    @ManyToOne(() => Bk_Product, product => product.id)
    product: Bk_Product;//商品id 
}